﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ParkingLot.Utility
{
   public class RectangleHelp
    {
        public static Rectangle? GetRectangle(string area)
        {
            string[] locations = area.Split(',');
            if (locations.Length < 4)
            {
                return null;
            }

            int x, y, width, height;
            //X坐标
            if (!int.TryParse(locations[0], out x))
            {
                return null;
            }
            //Y坐标
            if (!int.TryParse(locations[1], out y))
            {
                return null;
            }
            //Width
            if (!int.TryParse(locations[2], out width))
            {
                return null;
            }
            //Height
            if (!int.TryParse(locations[3], out height))
            {
                return null;
            }
            Rectangle rect = new Rectangle(x, y, width, height);

            if (rect.Width == 0 || rect.Height == 0)
            {
                return null;
            }
            return rect;
        }
    }
}
